import { SET_USER_INFO,UPDATE_USER_INFO} from '../actions/user';

const initState = {
    userId: '',
    faceUrl: '',
    nickName: '',
    role: 0
}

const userReducer = (state = initState, action: { type: String; payload: any }) => {
    switch (action.type) {
        case SET_USER_INFO:
          return {
              ...state,
              ...action.payload
          }        
        case UPDATE_USER_INFO:
          Object.entries(action.payload).forEach(([key, value]) => {
            state[key] = value;
          });
          return state
        default:
          return state;
        }
}

export default userReducer;